//-----------------------------------------首页------------------------------>
var token = localStorage.getItem('tok');
//展示信息上下滚轮显示
window.onload=function(){
    function roll (){
        var gonggaobox = document.getElementsByClassName('gonggaobox')[0];
        var nump=gonggaobox.getElementsByTagName('p');
        var offset=0;
        for(let i=0 ;i<nump.length;i++){
            var scrollheight =nump[i].offsetHeight*nump.length;
        }
        setInterval(function(){
            if(offset == scrollheight){
                offset = 0;
            }
            gonggaobox.style.marginTop = "-"+offset+"px";
            offset += 1;
        },80);
    }
    $.ajax({
            type: "GET",
            url: $host+'/api/open/config/loanMessages',
            async: true,
            dataType:'json',
            success: function(result){
                var data = result.data.message;
                var htmlNodes="";
                for(let i=0;i<data.length;i++){
                    htmlNodes+=`<p class="l">${data[i]}</p>`
                }
                document.getElementsByClassName('gonggaobox')[0].innerHTML=htmlNodes; 
                roll()
            },
            error:function(){
                console.log('首页滚轮信息接口错误')
            }
        });
}
//点击贷款
$(".btn ").click(function(){
    var ty=$('.shouquan').attr("test");
    //没有查看授权书
    if(ty=='bbb'||ty==undefined){
        layer.msg('请查看并同意授权书');
    }else{
        //同意授权书
        var amount=a;
        $.ajax({
            type: "POST",
            url: $host+'/api/app/loan/loanApply',
            data: {
                "amount":parseInt(amount),
                "limitTime":10,
                "limitType":1,
                "auditFee":$('.auditFee').html(),
                "profitFee":$('.profitFee').html(),
                "manageFee":$('.manageFee').html(),
                "actualAmount":$('.actualAmount').html(),
                'token':token
            },
            async: true,
            dataType:'json',
            success: function(res){
                console.log(res)
                let data = res.data;
                if(res.status===900000){
                    if(data.identityValid === 2){
                        window.location.href = 'shenhejd.html?token='+token
                    }else{
                        window.location.href = "shenfenyz.html?token="+token+'&amount='+amount+'&audiFee='+$('.auditFee').html()+'&profitFee='+$('.profitFee').html()+
                            '&manageFee='+$('.manageFee').html()+'&actualAmount='+$('.actualAmount').html()
                    }
                }
                if(res.status===500000){
                    window.location.href = 'woyaohk.html?token='+token
                }if(res.status===999998){
                    window.location.href = 'dengluy.html?token='+token
                }
            },
            error:function(){
                console.log('贷款接口有误');
            }
        });
    }
});


